package com.grey_zoo.lottery.view.fragment;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.grey_zoo.lottery.R;
import com.grey_zoo.lottery.global.GlobalValue;
import com.grey_zoo.lottery.view.weight.RoundImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

public class HomeFragment extends BaseFragment {
	private DisplayImageOptions options;
	private RoundImageView roundimg;
	private TextView moneytext;
	private TextView nametext;

	@Override
	public View initView(LayoutInflater inflater) {
		View view = inflater.inflate(R.layout.slide_left, null);
		roundimg = (RoundImageView) view.findViewById(R.id.slide_left_headimg);
		nametext = (TextView) view.findViewById(R.id.slide_left_nametextview);
		moneytext = (TextView) view.findViewById(R.id.slide_left_moneytextview);
		return view;
	}

	@Override
	public void initData(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		// System.out.println("jjjjjj");
		initoption();
        nametext.setText(GlobalValue.username+",用户你好");
        moneytext.setText("剩余金额为:"+GlobalValue.userMoney+"元");
		getBitmap();
	}

	public void initoption() {
		options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.ic_launcher) // resource or
				// drawable
				.showImageForEmptyUri(R.drawable.ic_launcher) // resource or
				// drawable
				.showImageOnFail(R.drawable.ic_launcher) // resource or
															// drawable
				.resetViewBeforeLoading(false) // default
				.delayBeforeLoading(1000).cacheInMemory(true) // default
				.cacheOnDisk(true) // default
				.considerExifParams(false) // default
				.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
				.bitmapConfig(Bitmap.Config.ARGB_8888) // default
				.displayer(new SimpleBitmapDisplayer()) // default
				.handler(new Handler()) // default
				.build();

	}

	private void getBitmap() {
		// TODO 自动生成的方法存根

		if (GlobalValue.info != null)
			if (GlobalValue.info.getImgUrl() != null) {
				GlobalValue.imageLoader.displayImage(
						GlobalValue.info.getImgUrl(), roundimg, options,
						new SimpleImageLoadingListener() {
							@Override
							public void onLoadingStarted(String imageUri,
									View view) {
								// TODO 自动生成的方法存根
								super.onLoadingStarted(imageUri, view);
							}

							@Override
							public void onLoadingComplete(String imageUri,
									View view, Bitmap loadedImage) {
								// TODO 自动生成的方法存根
								super.onLoadingComplete(imageUri, view,
										loadedImage);
							}

							@Override
							public void onLoadingFailed(String imageUri,
									View view, FailReason failReason) {
								// TODO 自动生成的方法存根
								super.onLoadingFailed(imageUri, view,
										failReason);
							}

						});
			}

	}

}
